// 订单管理
<template>
  <div class="order-management">
    <div class="top-card box">
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="订单编号">
          <el-input v-model="pageParams.id" placeholder="请输入订单编号"></el-input>
        </el-form-item>
        <el-form-item label="订单状态">
          <el-input v-model="pageParams.status" placeholder="请输入订单状态"></el-input>
        </el-form-item>
        <el-form-item label="付费状态">
          <div class="select">
            <el-select size="20" placeholder="请选择" v-model="pageParams.paymentStatus">
              <el-option label="未付" value="1"></el-option>
              <el-option label="已付" value="0"></el-option>
            </el-select>
          </div>
        </el-form-item>
        <el-form-item label="发件人姓名">
          <el-input placeholder="请输入发件人姓名" v-model="pageParams.senderName"></el-input>
        </el-form-item>
        <el-form-item label="发件人电话">
          <el-input placeholder="请输入发件人电话" v-model="pageParams.senderPhone"></el-input>
        </el-form-item>
        <el-form-item label="发件人地址">
          <div class="select">
            <el-select size="20" placeholder="请选择省" v-model="pageParams.receiverProvinceId"  @change="setCity">
              <el-option
                v-for="item in provinceList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
            <el-select placeholder="请选择市" v-model="pageParams.senderCityId" @change="setArea">
              <el-option
                v-for="item in cityOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
            <el-select placeholder="请选择县" v-model="pageParams.senderCountyId">
              <el-option
                v-for="item in areaOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </div>
        </el-form-item>
        <el-form-item label="收件人姓名">
          <el-input placeholder="请输入收件人姓名" v-model="pageParams.receiverName"></el-input>
        </el-form-item>
        <el-form-item label="收件人电话">
          <el-input placeholder="请输入收件人电话" v-model="pageParams.receiverPhone"></el-input>
        </el-form-item>
        <el-form-item label="收件人地址">
          <div class="select" v-if="provinceList">
            <el-select
              size="20"
              placeholder="请选择省"
              v-model="pageParams.receiverProvinceId"
              @change="setCity"
            >
              <el-option
                v-for="item in provinceList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
            <el-select placeholder="请选择市" v-model="pageParams.receiverCityId" @change="setArea">
              <el-option
                v-for="item in cityOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
            <el-select placeholder="请选择县" v-model="pageParams.receiverCountyId">
              <el-option
                v-for="item in areaOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </div>
        </el-form-item>
        <el-form-item class="btn">
          <el-button type="primary" @click="search">搜索</el-button>
          <el-button @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 表格 -->
    <div class="table box">
      <el-table :data="orderlist" stripe style="width: 100%">
        <el-table-column type="index" label="序号" />
        <el-table-column prop="id" label="订单编号" width="200" />
        <el-table-column prop="transportOrder.id" label="运单编号" width="200" />
        <el-table-column prop="createTime" label="下单时间" width="200" />
        <el-table-column prop="status" label="订单状态">
          <template v-slot="{row}">{{statusmap.get(row.status)}}</template>
        </el-table-column>
        <el-table-column prop="senderName" label="发件人姓名" width="100" />
        <el-table-column prop="senderPhone" label="发件人电话" width="200" />
        <el-table-column prop="senderAddress" label="发件人地址" width="200">
          <template></template>
        </el-table-column>
        <el-table-column prop="receiverName" label="收件人姓名" width="100" />
        <el-table-column prop="receiverPhone" label="收件人电话" width="200" />
        <el-table-column label="收件人地址" width="200">
          <template
            v-slot="{row}"
          >{{row.receiverProvince.name}}{{row.receiverCity.name}}{{row.receiverCounty.name}}</template>
        </el-table-column>
        <el-table-column prop="pickupType" label="取件类型">
          <template v-slot="{row}">{{row.pickupType===1?'网点自寄':'上门取件'}}</template>
        </el-table-column>
        <el-table-column prop="paymentMethod" label="付费类型">
          <template v-slot="{row}">{{row.paymentMethod===1?'预结':'到付'}}</template>
        </el-table-column>
        <el-table-column prop="paymentStatus" label="付费状态">
          <template v-slot="{row}">{{row.paymentStatus===1?'未付':'已付'}}</template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" width="200">
          <template v-slot="{ row }">
            <el-link
              style="color: #66c2ff"
              @click="$router.push(`/ordermanage/detail/${row.id}`)"
            >查看详情</el-link>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页组件 -->
      <el-row type="flex" style="height:60px" align="middle" justify="end">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="this.pageParams.page"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="this.pageParams.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="Number(counts)"
        ></el-pagination>
      </el-row>
    </div>
  </div>
</template>

<script>
import { getorderList, getprovinceList } from "@/api/ordermanage";
export default {
  name: "ordermanage",
  data() {
    return {
      areaOptions: [],
      pageParams: {
        id: "",
        status: "",
        receiverProvinceId: "",
        senderCityId: "",
        senderCountyId: "",
        receiverProvinceId: "",
        receiverCityId: "",
        receiverCountyId: "",
        paymentStatus: "",
        senderName: "",
        senderPhone: "",
        // senderAddress: '',
        receiverName: "",
        receiverPhone: "",
        // receiverAddress: '',
        page: 1,
        pageSize: 10,
      },
      provinceid: {
        id: "",
      },
      cityOptions: [],
      counts: 1, //总条数
      orderlist: [], //订单列表
      provinceList: [], //省份列表
      // 订单状态列表
      statusmap: new Map([
        [22000, "已关闭"],
        [23000, "待取件"],
        [23001, "已取件"],
        [23002, "网点自寄"],
        [23003, "网点入库"],
        [23004, "待装车"],
        [23005, "运输中"],
        [23006, "网点出库"],
        [23007, "待派送"],
        [23008, "派送中"],
        [23009, "已签收"],
        [23010, "拒收"],
        [230011, "已取消"],
      ]),
    };
  },
  created() {
    this.getorderList();
  },
  methods: {
    reset() {
      // 清空对象的值
      (this.pageParams.id = ""),
        (this.pageParams.status = ""),
        (this.pageParams.paymentStatus = ""),
        (this.pageParams.senderName = ""),
        (this.pageParams.senderPhone = ""),
        (this.pageParams.receiverName = ""),
        (this.pageParams.receiverPhone = ""),
        (this.pageParams.receiverProvinceId = ""),
        (this.pageParams.receiverCityId = ""),
        (this.pageParams.receiverCountyId = ""),
        (this.pageParams.receiverPhone = ""),
        this.pageParams.receiverProvinceId= "",
        this.pageParams.senderCityId= "",
        this.pageParams.senderCountyId= "",
        console.log("111");
    },
    async setArea(e) {
      const res = await getprovinceList(e);
      this.areaOptions = res.data;
    },
    async setCity(e) {
      console.log(e);
      const res = await getprovinceList(e);
      this.cityOptions = res.data;
    },
    async getorderList() {
      const res = await getorderList(this.pageParams);
      console.log(res.data.items);
      this.orderlist = res.data.items;

      this.counts = res.data.counts;
      const res1 = await getprovinceList();
      this.provinceList = res1.data;
    },
    // 分页器
    handleSizeChange(pageSize) {
      this.pageParams.pageSize = pageSize;
      this.getorderList();
    },
    handleCurrentChange(page) {
      this.pageParams.page = page;
      // console.log(page);
      this.getorderList();
    },
    // 搜索
    search() {
      // this.pageParams.id = this.searchcriteria.id
      // this.pageParams.status = this.searchcriteria.status

      console.log(this.pageParams.id);

      this.getorderList();
    },

    // // 搜索框
    // keywordChange() {
    //   // 防抖
    //   clearTimeout(this.timeId)
    //   this.timeId = setTimeout(() => {
    //     this.getorderList()
    //   }, 1500)
    //   // console.log(this.pageParams.keyword)
    // },
  },
};
</script>

<style lang="scss" scoped>
.order-management {
  padding: 0 20px;
  margin-top: 20px;
}
.top-card {
  // height: 142px;

  ::v-deep .demo-form-inline {
    display: flex;
    flex-wrap: wrap;
    .el-form-item {
      text-align: right;
      width: 30%;
      input {
        width: 320px;
      }
      .select {
        display: flex;
        width: 320px;
        & .el-select:nth-child(n + 2) {
          margin-left: 10px;
        }
        .el-select {
          position: relative;
          width: 100px;
          * {
            width: 100%;
          }
          i {
            position: absolute;
            right: -40px;
          }
          .el-input__inner {
            width: 105px;
          }
        }
      }
    }
    .btn {
      text-align: left;
      margin-left: 20px;
    }
  }
}
.table {
  margin-top: 20px;
}
.box {
  box-sizing: border-box;
  padding: 20px;
  background-color: #fff;
  border-radius: 10px;
  min-height: 50px;
}
</style>